package com.wuhongyu.service.impl;

import com.wuhongyu.common.MyCommon;
import com.wuhongyu.entity.Cons;
import com.wuhongyu.entity.Contr;
import com.wuhongyu.repository.CustomerDao;
import com.wuhongyu.repository.DictionaryDao;
import com.wuhongyu.repository.OrdersDao;
import com.wuhongyu.service.StatisticsService;
import com.wuhongyu.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 统计报表的业务逻辑
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private CustomerDao customerDao;
    @Autowired
    private DictionaryDao dictionaryDao;


    /**
     * 客户贡献分析
     * @param name
     * @param year
     * @return
     */
    @Override
    public List<Contr> contr(String name , String year){
        if(StringUtils.isEmpty(name) && StringUtils.isEmpty(year)){
            return customerDao.findContrAll();
        }else if(!StringUtils.isEmpty(name) && StringUtils.isEmpty(year)){
            return customerDao.findContrByName("%"+name+"%");
        }else if(StringUtils.isEmpty(name) && !StringUtils.isEmpty(year)){
            return customerDao.findContrByYear(year);
        }else {
            return customerDao.findContrByYearAndName(year,"%"+name+"%");
        }
    }

    /**
     * 客户构成分析
     * @param type
     * @return
     */
    @Override
    public List<Cons> cons(String type){
        if(MyCommon.GRADE.equals(type) ){
            return dictionaryDao.findByGrade();
        }else if(MyCommon.CREDITENAME.equals(type)){
            return dictionaryDao.findByCredit();
        }else {
            return dictionaryDao.findBySatisfied();
        }
    }

    /**
     * 客户服务分析
     * @param year
     * @return
     */
    @Override
    public List<Cons> server(String year){
        if(StringUtils.isEmpty(year)){
            return dictionaryDao.findServer();
        }else {
            return dictionaryDao.findServerByYear(year);
        }
    }



}